package net.ericaro.neojavagen;

import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;

public class JavaPartComposition {

	private static final Set<String> LINE_BREAKERS = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList("{", ";", "}", "*/")));

	protected String print(Object... parts) {
		StringBuilder sb = new StringBuilder();
		for (Object p : parts)
			if (p != null) {
				if (LINE_BREAKERS.contains(p))
					sb.append(p).append('\n');
				else if (p instanceof EnumSet) { // that's a little bit hacky, I have to fix it
					for (Object e : (EnumSet) p)
						sb.append(e).append(' ');
				} else
					sb.append(p).append(' ');
			}
		return sb.toString();
	}

}
